﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThouShaltNotBrick.Logic.Resources;
using ThouShaltNotBrick.Models;

namespace ThouShaltNotBrick.Logic.GeneralObjects
{
    public sealed class Campaign
    {
        #region Properties
        #region Name
        /// <summary>
        /// Name property.
        /// </summary>
        public string Name { get; private set; }
        #endregion

        #region LevelCount
        /// <summary>
        /// LevelCount property.
        /// </summary>
        public int LevelCount
        {
            get { return mLevels.Count; }
        }
        #endregion

        private List<Level> mLevels;
        #endregion

        #region Constructors
        public Campaign(
            string pCampaignName,
            GameResources pGameResources,
            BrickStatesAndTypes pBrickStatesAndTypes)
        {
            Initialize(pCampaignName, pGameResources, pBrickStatesAndTypes);
        }
        #endregion

        #region Methods
        private void Initialize(
            string pCampaignName,
            GameResources pGameResources,
            BrickStatesAndTypes pBrickStatesAndTypes)
        {
            CampaignData campaignData = pGameResources.GetCampaignData(pCampaignName);

            Name = campaignData.Name;

            List<string> levelNameList = campaignData.GetLevels();
            mLevels = levelNameList
                .Select(
                    ln => new Level(
                        pCampaignName,
                        ln,
                        pGameResources,
                        pBrickStatesAndTypes))
                .ToList();
        }

        public Level GetLevelByIndex(int pIndex)
        {
            return mLevels[pIndex];
        }
        #endregion
    }
}